package com.woniuxy.admin.controller;


import com.woniuxy.admin.entity.ScoreDiscount;
import com.woniuxy.admin.service.ScoreDiscountService;
import com.woniuxy.admin.util.JWTUtil;
import com.woniuxy.admin.util.TokenUtil;
import com.woniuxy.core.annotation.Permission;
import com.woniuxy.core.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ...
 * @since 2024年05月22日
 */
@RestController
@RequestMapping("/scoreDiscount")
@Api(tags="积分抵扣规则")
public class ScoreDiscountController {

    @Resource
    private ScoreDiscountService scoreDiscountService;

    @Resource
    private TokenUtil tokenUtil;

    /**
     * 查询积分抵扣规则
     * @return
     */
    @GetMapping("/selectScoreDiscount")
    @ApiOperation("查询积分抵扣规则")

      public Result selectScoreDiscount(){
        ScoreDiscount scoreDiscount = scoreDiscountService.getById(1);
        return Result.success("查询积分抵扣规则成功",scoreDiscount);
    }

    /**
     * 修改积分抵扣规则
     * @param discountRatio 抵扣比例1分抵扣多少钱
     * @param token
     * @return
     */
    @GetMapping("/updateScoreDiscount")
    @ApiOperation("修改积分抵扣规则")
    @ApiImplicitParam(name="discountRatio",value = "抵扣规则")
    @Permission(roles = {"超级管理员"})
    public Result updateScoreDiscount(BigDecimal discountRatio, @RequestHeader String token){
        Integer accountId = tokenUtil.getAccountId(token);
        scoreDiscountService.updateScoreDiscount(discountRatio,accountId);
        return Result.success("修改积分抵扣规则成功",null);
    }
}

